import Vue from 'vue'
import Vonic from 'vonic'
import store from './store'
import routes from 'entry/routes.js'
import util from 'service/util/index.js'
import filters from 'entry/filters.js'
import axios from 'axios'
import objectAssign from 'object-assign'
import mixins from 'entry/mixins.js'
import ajax from 'service/ajax/index.js'
import wxsdk from 'service/util/wxsdk.js'
require('./comps.js')

// 设置全局的变量
window.$axios = axios
window.$store = store
window.$mixins = mixins
window.$ajax = ajax
window.$wxsdk = wxsdk

// 注册filter
for (var key in filters) {
    Vue.filter(key, filters[key])
}

// ponyfill Object.assign
Object.assign = objectAssign

// 重置vonic中的样式以及一些全局的样式
require('asset/scss/vonic/export.scss')

/* 初始化项目 */
// setRem
util.rem()
// window.addEventListener('resize', function () {
//     util.rem()
// })
// 横屏提示
util.orientationchangeHint()

// 获取缓存在本地的用户信息
store.dispatch('userGetFromStorage')
// 白骑士指纹设备上传暂时不做
// store.dispatch('userConfitAjax')

Vonic.app.setConfig('afterEach', function (to, from) {
    document.title = to.meta.title || '随行贷'
    if (util.platform().wechat) {
        var url = window.location.protocol + '//' + window.location.host + '/#' + to.fullPath
        store.dispatch('wxReady', {
            success() {
                wxsdk.share()
            },
            url
        })
    }
})

Vue.use(Vonic.app, {
    routes,
    store
})

require('service/util/betterInput.js')